﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Data;

namespace Sample.PhotoBrowser.Components
{
    public class StringConcatenator : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                var stringList = (IList<String>)value;

                if (stringList.Count < 1)
                    return null;

                var separator = "; ";
                if (parameter != null)
                {
                    separator = parameter + " ";
                }
                var concatenatedString = stringList[0];

                for (int i = 1; i < stringList.Count; i++)
                {
                    concatenatedString = concatenatedString + separator + stringList[i];
                }

                return concatenatedString;
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }
    }
}
